<?php

namespace app\api\controller;

use app\admin\model\ShopCategory;
use app\api\model\ShopSettlement;
use app\common\controller\Api;
use app\common\model\Category;

/**
 * 店铺接口
 */
class Shop extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    //结算
    public function settlement()
    {
        $model = new ShopSettlement();
        // 获取当前日期
        $today = date("Y-m-d");

        // 将当前日期转换为当天开始的时间戳
        $time = strtotime($today);
        $res   = $model->settlement($time);

        $this->success('请求成功',$res);
    }

    /**
     * 分类
     *
     */
    public function category()
    {
        $list = ShopCategory::order('weigh desc')->select();

        $this->success('请求成功',$list);
    }

    //店铺列表
    public function lists()
    {
        $category_id = input('category_id',0);
        $keyword = input('keyword',0);
        $where = [];
        if ($category_id){
            $where['category_id'] = $category_id;
        }
        if ($keyword){
            $where['shop_name'] = ['like', '%' . $keyword . '%'];
        }
        $list = \app\admin\model\Shop::where($where)
            ->order('weigh desc')
            ->paginate(10);
        $this->success('',$list);
    }

    public function detail()
    {
        $id = input('id',0);
        $detail = \app\admin\model\Shop::get($id);
        $this->success('',$detail);
    }
}
